package net.chathu.airgw.crypto 
{
	/**
	 * ...
	 * @author ze
	 */
	public class Cipher 
	{
		
		protected var blockSize:int;
		protected var keySize:int;
		protected var seedLen:int;
		protected var key:Array;//protected byte key[];
		protected var bytecipher:Boolean;
		
		public function Cipher(i:int, j:int, k:int)
		{
			keySize = i;
			blockSize = j;
			bytecipher = (j == 1);
			seedLen = k;
			//key = new byte[i];
			key = new Array();
			for (var c:int = 0; c < i; c++)
			{
				key.push(0);
			}
			
		}

		/*public function Cipher(i:int, j:int)
		{
			this(i, j, i);
		}*/
		
		//OVERRIDE!
		public function copy():Cipher { return null; };
		
		public function setKey(newkey:Array):void
		{
			key = newkey;
			keySize = newkey.length;
		}
		
		public function getKey():Array
		{
			return key;
		}

		public function getKeyLen():int
		{
			return keySize;
		}

		public function getBlockSize():int
		{
			return blockSize;
		}

		public function getSeedLen():int
		{
			return seedLen;
		}
		
		public function generateKey():Array
		{

			var newkey:Array = new Array();
			
			for (var i:int = 0; i < seedLen; i++)
			{
				var randomByte:int = Math.floor(Math.random() * 256);
				newkey.push(randomByte);
			}
			
			setKey(newkey);
			return newkey;
		}

		public static function xorBlock( abyte0:Array, i:int, abyte1:Array, j:int, abyte2:Array, k:int, var_l:int):void
		{
			for ( var c:int = 0; c < var_l; c++)
			{
				abyte2[k + c] = (abyte0[i + c] ^ abyte1[j + c]) & 0xFF;
			}

		}

		/*public static function xorBlock(abyte0:Array, abyte1:Array, abyte2:Array):void
		{
			xorBlock(abyte0, 0, abyte1, 0, abyte2, 0, abyte0.length);
		}*/
		
		
		
		//OVERRIDE!
		//public abstract void encrypt(byte abyte0[], int i, byte abyte1[], int j, int k);
		public function encrypt(abyte0:Array, i:int, abyte1:Array, j:int, k:int):void {}

		public function encryptArray2(abyte0:Array, abyte1:Array):void
		{
			encrypt(abyte0, 0, abyte1, 0, abyte0.length);
		}

		public function encryptArray(abyte0:Array):void
		{
			encrypt(abyte0, 0, abyte0, 0, abyte0.length);
		}

		//OVERRIDE
		//public abstract void decrypt(byte abyte0[], int i, byte abyte1[], int j, int k);
		public function decrypt(abyte0:Array, i:int, abyte1:Array, j:int, k:int):void {}

		public function decryptArray2(abyte0:Array, abyte1:Array):void
		{
			decrypt(abyte0, 0, abyte1, 0, abyte0.length);
		}

		public function decryptArray(abyte0:Array):void
		{
			decrypt(abyte0, 0, abyte0, 0, abyte0.length);
		}


	}

}
